(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/Script/Spring.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, 'e390d6Dc2dN373XuZ1Tf3+L', 'Spring', __filename);
// Script/Spring.js

"use strict";

// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        holdStartTime: 0,
        MAX_IMPULSE: 50000, //最大冲量
        MIN_IMPULSE: 10000, //最小冲量
        RESTITUTION: 0.6
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad: function onLoad() {
        this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
            cc.log("[spring] TOUCH_START");
            this.holdStartTime = new Date().getTime();
        }, this);
        this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
            cc.log("[spring] TOUCH_END");
            if (this.ball != null) {
                var holdTime = new Date().getTime() - this.holdStartTime;
                var impulse = Math.min(this.MAX_IMPULSE, this.MIN_IMPULSE + this.MAX_IMPULSE * holdTime / 5000); //5秒蓄力最大
                var ballBody = this.ball.getComponent(cc.RigidBody);
                ballBody.applyLinearImpulse(cc.v2(0, impulse), ballBody.getWorldPosition());
                this.ball.getComponent(cc.PhysicsCircleCollider).restitution = this.RESTITUTION;
                cc.log("impulse=" + impulse);
            }
        }, this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
            cc.log("[spring] TOUCH_CANCEL");
            this.holdStartTime = 0;
        }, this);
        this.node.on(cc.Node.EventType.MOUSE_DOWN, function (event) {
            cc.log("[spring] MOUSE_DOWN");
        }, this);
    },
    start: function start() {},


    // 只在两个碰撞体开始接触时被调用一次
    onBeginContact: function onBeginContact(contact, selfCollider, otherCollider) {
        cc.log("[spring] onBeginContact");
        if (otherCollider.tag == 100) {
            cc.log("[spring] collison ball");
            this.ball = otherCollider;
            this.ball.getComponent(cc.PhysicsCircleCollider).restitution = 0;
        }
    },

    // 只在两个碰撞体结束接触时被调用一次
    onEndContact: function onEndContact(contact, selfCollider, otherCollider) {
        cc.log("[spring] onEndContact");
        if (otherCollider.tag == 100) {
            this.ball = null;
        }
    }

    // update (dt) {},
});

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=Spring.js.map
        